<?php
/**
 * Request class definition
 * 
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MutantVole
 */

/**
 * Base class for pagelets. Should be extended for each individual pagelet.
 * @package MutantVole
 * @subpackage Pages
 */
abstract class Pagelet {

    /**
	 * Create the presenter and anything else the pagelet needs to load before
	 * the request can be handled
	 */
    abstract public function Setup();
    
    /**
     * Setup the pagelet and attach request handlers
     * @param Request $request
     * @param iSession $session
     * @param iViewRenderer $renderer
     */
    public function Display(Request $request = null, iSession $session = null, iViewRenderer $renderer = null) {
        $this->request = $request;
    	$this->session = $session;
	    $this->renderer = $renderer;
	    
        $this->Setup();		
        
        if (is_array($this->subPagelets)) {
            foreach ($this->subPagelets as $pagelet) {
                $pagelet->Display($this->request, $this->session, $this->renderer);
            }
        }
    }
    
    /**
     * Attach a pagelet as a child to this one
     * @param Pagelet $pagelet
     */
    public function AttachPagelet(Pagelet $pagelet) {
        $this->subPagelets[] = $pagelet;
    }
    
    /**
     * list of attached pagelets
     * @var array
     */
    protected $subPagelets;
}
?>
